
//声明函数
function add(a: number, b: number): number{
  return a + b;
}

//箭头函数
let minus = (a: number, b: number): number => {
  return a - b;
}

//匿名函数
let times = function(a: number, b:number){
  return a * b;
}

//为变量声明函数的类型                  设置函数返回值类型
let divide : (a:number, b: number) => number;
let divide2 : (a:number, b: number) => void;

divide = (x:number, y:number): number => {
  return x / y;
}

//完整体 
let fn: (a:number, b:number) => number  = (x:number,y:number):number => {
  return x 
} 


//参数可选 字符串截取
function slice(str: string, start: number, end ?: number){
  return str.slice(start, end);
}

// console.log(slice('12312312312', 2));
// console.log(slice('12312312312', 2, 6));

//声明函数构建 手机号              +86
function buildPhone(code:string, area:string='+86'){
  return area + code;
}
console.log(buildPhone('1587452536', '+68'))
console.log(buildPhone('1587452536'))

//rest 参数  jia(1,2,3,4,5,5,6,7);
function jia(a:number, b:number, ...args: number[]){
  //所有的参数
  let arr: number[] = [a, b, ...args];
  //遍历
  let result = arr.reduce((prev, cur) => {
    return prev + cur;
  })
  return result;
}

console.log(jia(1,2,3,4,5,6,7));




export {}